﻿using AutoMapper;
using EFEntity;
using ISerives;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Serives
{
     public  class config_public_charServices: Iconfig_public_charSerives
    {
        private readonly MyDbContext myDbContext;
        private readonly IMapper mapper;
        public config_public_charServices(MyDbContext myDbContext, IMapper mapper)
        {
            this.myDbContext = myDbContext;
            this.mapper = mapper;
        }
        public async Task<int> Delete(int id)
        {
            config_public_char ef = new config_public_char()
            {
                 pbc_id = id
            };
            myDbContext.ZWMC.Attach(ef);
            myDbContext.ZWMC.Remove(ef);
            int num = await myDbContext.SaveChangesAsync();
            return num;
        }


        public async Task<List<Mconfig_public_char>> Select()
        {
            List<Mconfig_public_char> list1 = new List<Mconfig_public_char>();
            await Task.Run(() =>
            {
                List<config_public_char> list = myDbContext.ZWMC.ToList();
                list1 = mapper.Map<List<Mconfig_public_char>>(list);

            });
            return list1;
        }
    }
}
